Imports System.Data
Partial Class Admin_frmTabEmployee
    Inherits System.Web.UI.Page
    Dim conn As New SqlString()
    Dim _BO As New Bo()
    Dim _EmployeeVO As New EmployeeVo()
    Dim _EmployeeId As String
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            _EmployeeVO.EmployeeId = txtEmployeeId.Text
            _EmployeeVO.Password = txtPassword.Text
            _EmployeeVO.FirstName = txtFirstName.Text
            _EmployeeVO.LastName = txtLastName.Text
            _EmployeeVO.Address = txtAddress.Text
            _EmployeeVO.PhoneNumber = txtPhoneNumber.Text
            _EmployeeVO.EmailId = txtEmailId.Text
            _EmployeeVO.Designation = txtDesignation.Text
            _EmployeeVO.LastLogin = System.DateTime.Now.ToShortDateString
            _BO.InsertEmployee(_EmployeeVO)
            MsgBox("Employee inserted")
            _EmployeeId = txtEmployeeId.Text
            ClearAll()
            'Session("EmpId") = _EmployeeId
            'Response.Redirect("frmHome.aspx", False)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub ClearAll()
        txtEmployeeId.Text = ""
        txtPassword.Text = ""
        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtAddress.Text = ""
        txtPhoneNumber.Text = ""
        txtEmailId.Text = ""
        txtDesignation.Text = ""
        MsgBox("Employee inserted")
    End Sub
    Sub GridData()
        Dim dtEmployee As DataTable
        dtEmployee = _BO.getEmployeeDetails()
        gdEmployee.DataSource = dtEmployee
        gdEmployee.DataBind()
    End Sub
    Protected Sub gdEmployee_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdEmployee.EditCommand
        Session("EmpId") = _EmployeeId
        Response.Redirect("frmModifyEmployee.aspx?EmployeeId=" & e.Item.Cells(0).Text)
    End Sub
    Protected Sub gdEmployee_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles gdEmployee.DeleteCommand
        _BO.DeleteEmployee(e.Item.Cells(0).Text)
        Response.Redirect("frmTabEmployee.aspx")
    End Sub
    Protected Sub ImageAdd_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageAdd.Click
        panel2.Visible = True
        panel4.Visible = False
    End Sub

    Protected Sub ImageEdit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageEdit.Click
        panel2.Visible = False
        panel4.Visible = True
        GridData()
    End Sub

    Protected Sub gdEmployee_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles gdEmployee.PageIndexChanged
        gdEmployee.CurrentPageIndex = e.NewPageIndex
        GridData()
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("../Client/frmLogin.aspx")
        End If
        If Not Page.IsPostBack Then
            panel2.Visible = False
            panel4.Visible = False
            GridData()
        End If
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtEmployeeId.Text = ""
        txtPassword.Text = ""
        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtAddress.Text = ""
        txtPhoneNumber.Text = ""
        txtEmailId.Text = ""
        txtDesignation.Text = ""
    End Sub
End Class